package jin.si.com.xc;

import org.apache.poi.ss.formula.functions.T;

/**
 * @description:
 * @ClassName Lianxi
 * @Author MT
 * @Date 2021/7/3 12:56
 **/
public class Lianxi implements Runnable{
    private static int number=200;
    Object obj=new Object();

    @Override
    public void run() {
       while (true){
           //同步代码块锁
           if(number%2==0){
               synchronized (Lianxi.class) {
                   if (number > 0) {
                       System.out.println(Thread.currentThread().getName() + "：偶数：" + number);
                       number--;
                   }
               }
           }else{
               method();
           }
       }

     }

     //同步方法锁
     public synchronized void method(){
        if(number > 0){
            System.out.println(Thread.currentThread().getName()+"：奇数："+number);
            number--;
        }
     }

     //静态锁 锁的对象是字节码文件对象
     public static synchronized void method1(){
         if(number>0){
             System.out.println(Thread.currentThread().getName()+"：奇数："+number);
             number--;
         }
     }


}




